<template>
  <div class="myContainer">
    <!-- 头部标题 start -->  
    <el-row class="myBorderBottom">
      <el-col :span="7" class="myTitleText myLineHeight_40px">{{title}}</el-col>
      <el-col :span="17" class="myTextAlignRight">
        <el-button type="primary" class="myBgGreen" @click="add">新增</el-button>
      </el-col>
    </el-row>
    <!-- 头部标题 end -->
    <el-row :gutter="10" class="myPaddingTop_10px">
      <el-col :span="4">
        <el-input placeholder="请输入关键词" v-model="kw"></el-input>
      </el-col>
      <el-col :span="4">
        <el-button type="primary" @click="search">查询</el-button>
      </el-col>
    </el-row>
    
    <el-row class="myPaddingTop_10px">
      <el-col :span="24">
        <template>
          <el-table
            border
            :data="list"
            :stripe = true
            v-loading="loading"
            style="width: 100%">
            <el-table-column
              label="序号"
              type="index"
              width="100">
            </el-table-column>
            <el-table-column
              label="姓名"
              prop="admin_name">
            </el-table-column>
            <el-table-column
              label="联系电话"
              prop="admin_phone">
            </el-table-column>
            <el-table-column
              label="部门"
              prop="dept_name">
            </el-table-column>
            <el-table-column
              label="职务"
              prop="role_name">
            </el-table-column>
            <el-table-column
              label="管理资产区域"
              prop="admin_area_name">
            </el-table-column>
            <el-table-column
              label="功能操作"
              width="100">
              <template scope="scope">
                <el-button class="look" type="text" size="small" @click="update(scope.row.admin_id)">编辑</el-button> |
                <el-button class="look" type="text" size="small" @click="ondelete(scope.row.admin_id)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-col>
    </el-row>
    
    <div class="block">                    
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page_num"
        :page-sizes="[10, 15]"
        :page-size="page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>

  </div>
</template>     
  
<style scoped>
  .myBorderBottom{
    border-bottom:1px solid #dbdbdb;
    padding-bottom: 5px;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleText{
    font-weight: 500;
    font-size: 16px;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myPaddingTop_10px{
    padding-top: 10px;
  }  
  .myred{
    color: #f00;
    font-size: 12px;
  }
  .myMarginBottom_10px{
    margin-bottom: 10px;
  }
  .myLeftMsg{
    line-height: 40px;
    text-align: right;
  }
</style>

<script>
  import { getAdmin , deleteAdmin } from "@/api/assets";
  export default {
    data(){
      return{
        title:"资产管理员设置",
        page_num:1,
        page_size:10,
        total:null,
        list:[],
        loading:false,
        kw:""

      }
    },
    components: {

    },
    created(){
      document.title=this.title;
      this.ongetAdmin();
    },
    watch: {
      
    },
    methods:{
      handleSizeChange(val) {//每页条数控制
        this.page_size = val;
        this.ongetAdmin();
      },
      handleCurrentChange(val) {//每页
        this.page_num = val;
        this.ongetAdmin();
      },
      add(){
        this.$router.push({
          path:"assetManagerMGTComonents",
          query:{
            type:"add"
          }
        })
      },
      update(id){
        this.$router.push({
          path:"assetManagerMGTComonents",
          query:{
            type:"update",
            id:id
          }
        })
      },
      ondelete(id){
        let vm=this;
        vm.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteAdmin(id).then(response => {
            vm.$message.success("执行成功！");
            vm.ongetAdmin();
          }).catch(error => {
            vm.$message.error("执行失败！"+error.response.data.error_msg);
          })
        }).catch(() => {
          vm.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
      },
      search(){
        this.ongetAdmin();
      },
      ongetAdmin(){
        let vm=this;
        let params={
          keyword:encodeURI(vm.kw),
          page_num:vm.page_num,
          page_size:vm.page_size
        }
        vm.loading=true;
        getAdmin(params).then(response => {
          let res=response.data;
          vm.list=res.rows;
          vm.page_size=res.page_size;
          vm.page_num=res.page_num;
          vm.total=res.total;
          vm.loading=false;
        }).catch(error => {
          vm.loading=false;
          vm.$message.error("执行失败！"+error.response.data.error_msg);
        })
      }
      
    }
}
</script>

